Imports System.Data
Imports System.Net.Mail

Partial Class Contact
  Inherits System.Web.UI.Page

    Protected Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Dim dao As New DAOAdmin.USER_MSTR_DAO
        Dim vo As New DAOAdmin.USER_MSTR_VO

        Dim strName As String = ""
        Dim strEmail As String = ""

        vo.USER_NAME = Session("UserName")
        Dim dt As DataTable = dao.Search(vo)

        If dt.Rows.Count > 0 Then
            strName = Trim(dt.Rows(0)("USER_LAST_NAME")) & ", " & Trim(dt.Rows(0)("USER_FIRST_NAME")) & " : "
            strEmail = Trim(dt.Rows(0)("EMAIL_ADDRESS"))

            Call Sendmail(strName, strEmail)
        End If

        dt = Nothing
        vo = Nothing
        dao = Nothing

        Response.Redirect("~/Default.aspx")
    End Sub

    Private Sub Sendmail(ByVal strName As String, ByVal strEmailFrom As String)
        Dim x As New SmtpClient
        Dim cfunc As New CIMSfunc

        Try
            With x
                .Host = cfunc.GetSMTPServer()
                .Port = 25
                .UseDefaultCredentials = True
                x.Send(strEmailFrom, cfunc.GetAdminEmail, txtSubject.Text, strName & vbCrLf & Trim(txtMessage.Text))
            End With
        Catch ex As Exception
            System.Diagnostics.Debug.Print(ex.Message.ToString)
        End Try

        cfunc = Nothing
        x = Nothing
    End Sub
End Class
